﻿using System.Net;

namespace Infrastructure.WebApi
{
    public class BusinessException : Exception
    {
        public ApiCode Code { get; } = ApiCode.Error;
        public HttpStatusCode HttpStatusCode { get; } = HttpStatusCode.BadRequest;

        public BusinessException(string message) : base(message)
        {
        }

        public BusinessException(ApiCode code, string message = "") : base(message)
        {
            Code = code;
        }
        public BusinessException(HttpStatusCode code, string message = "") : base(message)
        {
            HttpStatusCode = code;
        }

        public static void Throw(string message = "")
        {
            throw new BusinessException(message);
        }

        public static void Throw(ApiCode code, string message = "")
        {
            throw new BusinessException(code, message);
        }
        public static void Throw(HttpStatusCode code, string message = "")
        {
            throw new BusinessException(code, message);
        }
    }
}
